<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<div class="portlet box blue">
	<div class="portlet-title">
		<div class="caption">
			<i class="fa fa-gift"></i>安全库存设置
		</div>
	</div>
	<div class="portlet-body form">
		<form id="safeWarningForm" class="form-horizontal form-bordered"
			action="/safeWarning/save" method="post">
			<%-- <div class="form-group">
				<label class="col-md-3 control-label">仓库：</label>
				<div class="col-md-4">
					<select name="warehouseId" class="form-control">
						<c:forEach items="${warehouses }" var="warehouse" varStatus="status">
							<option value="${warehouse.id }"> ${warehouse.name }</option>
						</c:forEach>
					</select>
				</div>
			</div> --%>
			<div class="form-group">
				<label class="col-md-3 control-label">我司货号:</label>
				<div class="col-md-4">
					<select name="stockId" class="form-control">
						<c:if test="${not empty safeWarning}">
							<option value="${safeWarning.stock.id }">${safeWarning.stock.warehouse.name } ： ${safeWarning.stock.product.code }</option>
						</c:if>
						<c:forEach items="${stocks}" var="stock" varStatus="status">
							<option value="${stock.id }">${stock.warehouse.name } ： ${stock.product.code }</option>
						</c:forEach>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-3 control-label">合理库存:</label>
				<div class="col-md-4">
					<input type="text" name="reasonableStock" id="reasonableStock" class="form-control"
						value="${safeWarning.reasonableStock}" maxlength="10" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-3 control-label">预警上限:</label>
				<div class="col-md-4">
					<input type="text" name="warningMax" id="warningMax" class="form-control"
						value="${safeWarning.warningMax}" maxlength="10" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-3 control-label">预警下限:</label>
				<div class="col-md-4">
					<input type="text" name="warningMin" id="warningMin" class="form-control"
						value="${safeWarning.warningMin}" maxlength="10" />
				</div>
			</div>

			<div class="form-group">
				<label class="col-md-3 control-label">备注:</label>
				<div class="col-md-4">
					<textarea class="form-control" rows="3">${safeWarning.description}</textarea>
				</div>
			</div>
			<input type="hidden" value="${safeWarning.id }" name="id">
			<div class="form-actions">
				<div class="col-md-9 col-md-offset-3">
					<button type="button" class="btn btn-primary" onclick="saveSafeWarning()">
						保存</button>
					<button type="reset" class="btn btn-default" onclick="cancel()">
						关闭</button>
				</div>
			</div>
		</form>
	</div>
</div>
<script type="text/javascript"
	src="<c:url value="/static/custom/datepicker-util.js"></c:url>"></script>
<script type="text/javascript">
	$(function() {
		$('#putForm').validate();
	});
	function saveSafeWarning() {
		if ($('#reasonableStock').val().trim() == "") {
			$('#reasonableStock').val("");
			alert("合理库存不能为空");
			return false;
		}
		if ($('#warningMax').val().trim() == "") {
			$('#warningMax').val("");
			alert("预警上限不能为空");
			return false;
		}
		if ($('#warningMin').val().trim() == "") {
			$('#warningMin').val("");
			alert("预警下限不能为空");
			return false;
		}
		if ($('#safeWarningForm').valid()) {
			$.ajax({
				type : 'post',
				url : '<c:url value="/safeWarning/save"></c:url>',
				data : $('#safeWarningForm').serialize(),
				dataType : 'json',
				success : function(data) {
					alert(messages[data.result]);
					search();
					$(".panel-search").show();
				}
			});

		}
	}
</script>